<?php
/**
 * 汽车频道
 * @author zengnz
 *
 */
class AutoAction extends CommonAction
{
	/**
	 * 首页
	 */
	public function index() {
		$Model = D('CarCategory');
		$categorys = $Model -> getCategorys();

		$this -> assign('categorys', $categorys);
		$this -> display();
	}
	
	public function sub() {
		
		$this -> display();
	}
	
	/**
	 * 内容
	 */
	public function detail() {
	
		$this -> display();
	}
	
	/**
	 * 品牌
	 */
	public function brands() {
		$CarCategory = D('CarCategory', 'Logic');
		
		$brands = $CarCategory -> getCarBrands();
		if (!$brands || !is_array($brands))
			$this -> error('品牌记录不存在！');
		
		$categorys = $CarCategory -> getCarCategorys();
		if (!$categorys || !is_array($categorys))
			$this -> error('车型记录不存在！');

		//获取汽车类型
		$carTypes = $CarCategory -> getCarTypes();
		
		$allCategorys = array();
		foreach ($categorys as $category) {
			$category['low_price'] = ($category['low_price']!=0) ? tenThousandPrice($category['low_price']) : 0;
			$category['high_price'] = ($category['high_price']!=0) ? tenThousandPrice($category['high_price']) : 0;
			$category['car_type'] = $carTypes[$category['type']];
			
			$allCategorys[$category['brand_id']][] = $category;
		}
		
		$allLetters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
		$haveLetters = array(); // 打头字母
		$allBrands = array();
		foreach ($brands as $brand) {
			$haveLetters[$brand['begin_width']] = $brand['begin_width'];
			
			if ($brand['pid'] == 0) {
				$allBrands[$brand['begin_width']]['letter'] = $brand['begin_width']; 
				$allBrands[$brand['begin_width']]['list'][$brand['id']]['par'] = $brand;
			} else {
				$allBrands[$brand['begin_width']]['list'][$brand['pid']]['sub'][$brand['id']]['brand'] = $brand;
				$allBrands[$brand['begin_width']]['list'][$brand['pid']]['sub'][$brand['id']]['categorys'] = $allCategorys[$brand['id']];
			} 
		}
		
		$letters = array();
		foreach ($allLetters as $val){
			if (in_array($val, $haveLetters))
				$letters[$val] = 1;
			else
				$letters[$val] = 0;
		}
		
		$this -> assign('brands', $allBrands);
		$this -> assign('letters', $letters);
		$this -> display();
	}
	
	/**
	 * 点击某个汽车品牌进入，品牌百科，品牌下车型新闻，文章，相关视频，经销商
	 */
	public function brandDetail() {
		
		
	}
	
	/**
	 * 点击某款车进入，可以看到该款车的所有车型，相关文章，视频，降价情况，二手车，租车，论坛，评论，图片，4S店，我浏览过的车型（缓存），看过这款车的人还看过车型（缓存）
	 */
	public function carDetail() {
		$id = $this -> getParam('id');
		echo $id;exit;
		
		$this -> display();
	}
	
	/**
	 * 汽车百科
	 */
	public function paike() {
		$this -> display();
	}
	
	
	/**
	 * 汽车出租
	 */
	public function rent() {
		
		$this -> display();
	}
	
	/**
	 * 租车门店
	 */
	public function rentShop() {
		
	}
	
	/**
	 * 租车详细信息
	 */
	public function rentDetail() {
		
		$this -> display();
	}
	
	/**
	 * 二手车交易
	 */
	public function transaction() {
		
		$this -> display();
	}
	
	/**
	 * 二手车列表
	 */
	public function transactionList() {
		
		$this -> display();
	}
	
	/**
	 * 二手车详细信息
	 */
	public function transactionDetail() {

		$this -> display();
	}
	
}